# coding: utf-8
from flask_sqlalchemy import SQLAlchemy


db = SQLAlchemy()



class HkBasePoint(db.Model):
    __tablename__ = 'hk_base_point'

    id = db.Column(db.BigInteger, primary_key=True, info='基础点位主键')
    work_section_id = db.Column(db.BigInteger, info='工段主键')
    production_line_id = db.Column(db.BigInteger, info='产线主键')
    work_station_id = db.Column(db.BigInteger, info='工位主键')
    device_channel_id = db.Column(db.BigInteger, info='设备通道主键')
    point_name = db.Column(db.String(200, 'utf8mb4_general_ci'), info='点位名称')
    point_alias = db.Column(db.String(200, 'utf8mb4_general_ci'), info='点位别名')
    point_address = db.Column(db.String(200, 'utf8mb4_general_ci'), info='点位地址')
    biz_name = db.Column(db.String(200, 'utf8mb4_general_ci'), info='业务名称')
    point_type = db.Column(db.String(50, 'utf8mb4_general_ci'), info='点位类型，1：报警，2：RFID，以实际业务为准')
    alarm_type = db.Column(db.String(50, 'utf8mb4_general_ci'), info='报警类型')
    pline_stoped = db.Column(db.Integer, info='是否停线')
    refresh_interval = db.Column(db.Integer, info='刷新频率，单位：毫秒')
    point_desc = db.Column(db.String(500, 'utf8mb4_general_ci'), info='点位描述')
    real_value = db.Column(db.String(100, 'utf8mb4_general_ci'), info='实时点位值')
    value_update_time = db.Column(db.DateTime, info='点位值更新时间')
    create_time = db.Column(db.DateTime, info='创建时间')
    update_time = db.Column(db.DateTime, info='更新时间')
    create_person = db.Column(db.String(255, 'utf8mb4_general_ci'), info='创建人')
    create_person_id = db.Column(db.BigInteger, info='创建人id')
    update_person = db.Column(db.String(255, 'utf8mb4_general_ci'), info='更新人')
    update_person_id = db.Column(db.BigInteger, info='更新人id')

    def __str__(self):
        return "{},{}".format(self.point_name, self.point_address)



class HkDeviceChannel(db.Model):
    __tablename__ = 'hk_device_channel'

    id = db.Column(db.BigInteger, primary_key=True, info='设备通道主键')
    channel_name = db.Column(db.String(200, 'utf8mb4_general_ci'), info='通道名称')
    channel_type = db.Column(db.String(50, 'utf8mb4_general_ci'), info='通道类型，默认：OPCUA')
    device_name = db.Column(db.String(200, 'utf8mb4_general_ci'), info='设备名称')
    device_model = db.Column(db.String(100, 'utf8mb4_general_ci'), info='设备型号')
    device_address = db.Column(db.String(200, 'utf8mb4_general_ci'), info='设备地址')
    device_port = db.Column(db.Integer, info='访问端口')
    refresh_interval = db.Column(db.Integer, info='刷新频率，单位：毫秒')
    namespace = db.Column(db.String(100, 'utf8mb4_general_ci'), info='命名空间')
    remark = db.Column(db.String(500, 'utf8mb4_general_ci'), info='备注')
    create_time = db.Column(db.DateTime, info='创建时间')
    update_time = db.Column(db.DateTime, info='更新时间')
    create_person = db.Column(db.String(255, 'utf8mb4_general_ci'), info='创建人')
    create_person_id = db.Column(db.BigInteger, info='创建人id')
    update_person = db.Column(db.String(255, 'utf8mb4_general_ci'), info='更新人')
    update_person_id = db.Column(db.BigInteger, info='更新人id')
